package com.bw.kf.all2211a.fg.fgviewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.kf.mvvm.base.BaseRepo
import com.bw.kf.mvvm.entity.ResetEntity
import com.bw.kf.mvvm.entity.SendCodeEntity
import com.google.gson.Gson
import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

class ResetViewMode:BaseRepo() {
    val success= MutableLiveData<ResetEntity>()
    val fall= MutableLiveData<String>()
    fun getReset(phone:String,code:String,password:String){
        viewModelScope.launch {
            try {
                val map=HashMap<String,Any>()
                map.put("account",phone)
                map.put("captcha",code)
                map.put("password",password)
                val gson= Gson().toJson(map)
                val body = RequestBody.create("application/json".toMediaTypeOrNull(),gson)
                success.value=aPiText.reset(body)
            }catch (e:Exception){
                fall.postValue(e.message)
            }
        }
    }
    val successC=MutableLiveData<SendCodeEntity>()
    val fallC=MutableLiveData<String>()
    fun sendCode(phone:String){
        viewModelScope.launch {
            try {
                successC.value=aPiText.sendCode(phone)
            }catch(e:Exception) {
                fallC.value=e.message
            }
        }
    }
}